package com.lkd.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.dto.SkuClassDto;
import com.lkd.entity.SkuClass;
import com.lkd.mapper.SkuClassMapper;
import com.lkd.result.PageBean;
import com.lkd.service.SkuClassService;
import com.lkd.vo.SkuClassVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SkuClassServiceImpl implements SkuClassService {
    @Autowired
    private SkuClassMapper skuClassMapper;

    @Override
    public void save(SkuClassDto skuClassDto) {
        skuClassMapper.insert(skuClassDto);
    }

    @Override
    public PageBean<SkuClassVo> findByCondition(String className, Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        Page<SkuClassVo> skuClassResult = skuClassMapper.selectBycondition(className);
        Long totalPage = (long) skuClassResult.getPages();
        return new PageBean<SkuClassVo>(pageIndex,pageSize,totalPage,skuClassResult.getTotal(),skuClassResult);
    }

    @Override
    public SkuClassVo findByClassId(Integer classId) {
        SkuClassVo skuClassVo = skuClassMapper.selectByClassId(classId);
        return skuClassVo;
    }

    @Override
    public void update(SkuClassDto skuClassDto) {
        SkuClass skuClass = BeanUtil.toBean(skuClassDto, SkuClass.class);
        skuClassMapper.update(skuClass);
    }

    @Override
    public void delete(Integer classId) {
        skuClassMapper.delete(classId);
    }
}
